package com.paho.handler;

import org.springframework.stereotype.Component;

import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

/**
 *  分发处理器实现
 * @Author wdy
 * @Date 2023/9/19
 **/
@Component
public class MqttDistributeImpl implements MqttDistribute {

    private final ConcurrentHashMap<String, MqttHandler> data = new ConcurrentHashMap<>();

    @Override
    public void putHandlerBean(String topic, MqttHandler mqttHandler) {
        data.put(topic, mqttHandler);
    }

    @Override
    public Set<String> getTopics() {
        return data.keySet();
    }

    @Override
    public void distribute(String topic, String message) {
        //分发消息
        data.get(topic).process(topic, message);
    }
}
